package meterMonitor.biz;

import meterMonitor.framework.context.CurrentUser;
import meterMonitor.mapper.AuthMapper;
import meterMonitor.mapper.UserAuthMapper;
import meterMonitor.model.Auth;
import meterMonitor.model.UserAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/2/22 0022.
 */
@Service
public class UserAuthBiz extends BaseBiz {
    @Autowired
    UserAuthMapper userAuthMapper;
    @Autowired
    AuthMapper authMapper;

    public void insertUserAuth(CurrentUser currentUser){
        List<String> listCode = currentUser.getUserAuthList();
        if (listCode == null || listCode.size() == 0) {
            return;
        }
        String longinName = currentUser.getLoginName();
        List<UserAuth> list = new ArrayList<>();
        for (String code:listCode){
            UserAuth userAuth = new UserAuth();
            userAuth.setLoginName(longinName);
            userAuth.setAuthCode(code);
            list.add(userAuth);
        }
        userAuthMapper.insertUserAuth(list);
    }

    public List<Auth> getAuths(){
        return authMapper.selectAll();
    }

}
